<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once(APPPATH. 'controllers/layout.php');

class Products extends Layout
{
	public function __construct()
	{
		parent::__construct();

	}


    public function checkSlug()
    {
        $uri = $this->uri->segment(1);

        $checkSlug = $this->category_model->CheckSlug(mb_strtolower(url_title(removesign($uri))));
        if($checkSlug) {
            $this->category();
        }else {
            $this->deproduct();
        }
    }
	
	public function index()
	{
        $url_Filter = $this->uri->uri_string();
        $filter = array();
        if (isset($_GET) && $_GET != null){
            //$url_Filter .= "/?p=".isset($_GET['p']) ? $_GET['p'] :  0 ."&h=". $_GET['h'] ? $_GET['h'] : 0 ."&l=".$_GET['l'] ? $_GET['l'] : 0 ."&c=".$_GET['c'] ? $_GET['c'] : 0 ."&t=".$_GET['t'] ? $_GET['t'] : 0 ."&pr=".$_GET['pr'] ? $_GET['pr'] : 0;
            $filter['p'] = $p = isset($_GET['p']) ? $_GET['p'] :  0 ;
            $filter['h'] = $h = isset($_GET['h']) ? $_GET['h'] :  0 ;
            $filter['l'] = $l = isset($_GET['l']) ? $_GET['l'] :  0 ;
            $filter['c'] = $c = isset($_GET['c']) ? $_GET['c'] :  0 ;
            $filter['t'] = $t = isset($_GET['t']) ? $_GET['t'] :  0 ;
            $filter['pr'] = $pr = isset($_GET['pr']) ? $_GET['pr'] :  0 ;

            $url_Filter .= "/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
        }else {
            $url_Filter .= "/?p=0&h=0&l=0&c=0&t=0&pr=0";
        }

		$config['per_page'] = 20;
		if($this->input->post('search')){
			$search[] = $this->input->post('search');
			$page = 0;
		}else{
			$search = $this->input->get('search');
		}
		$page = $this->uri->segment(2);
	
		$result = $this->product_model->getAllSearchProduct($search, $page, $config['per_page'], $filter);

		$this->load->library('pagination');
		
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];


		if($filter != null){
            $config['first_url'] = $config['base_url']."/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
			$this->pagination->suffix = "/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
		}

		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		
		$config['first_link'] = 'Trang đầu';
		$config['last_link'] = 'Trang sau';
		
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
		
		$data['tbl_products'] = $result['tbl_products'];

        $slider = $this->utility_model->selectSlider('tbl_slider');
		
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['meta'] = $this->load->view('home/meta', '', TRUE);
		$this->_data['main_container'] = $this->load->view('frontend/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
                'url_Filter' => $url_Filter,
                'silders' => $slider,
		), true);
		
// 		/$this->_data['seo'] = "demo";
		$this->load->view('frontend/layout_view', $this->_data);
	}
	
	public function index1()
	{
		$config['per_page'] = 6;
		if($this->input->post('search')){
			$search = $this->input->post('search');
			$page = 0;
		}else{
			$search = $this->input->get('search');
		}
		$page = $this->uri->segment(2);
	
		$result = $this->product_model->getAllSearchProductt($search, $page, $config['per_page']);
	
		$this->load->library('pagination');
	
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi-t';
		$config['total_rows'] = $result['total_record'];
		
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
	
	
	public function aprice()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchProductPrice($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		//echo $result['sql'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
		
		$data['tbl_products'] = $result['tbl_products'];
		
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
	
	public function origin()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchProductorigin($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		//echo $result['sql'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
				
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
	
	public function brand()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchProductbrand($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		//echo $result['sql'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
	
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
	
	
	public function capacity()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchProductcapacity($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		//echo $result['sql'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
	
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
    
    
    
    public function features()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchProductfeatures($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		//echo $result['sql'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
        $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		$this->_data['main_container'] = $this->load->view('home/allproducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
	
		), true);
		$this->load->view('home/layout_view', $this->_data);
	}
	
	
	public function category()
	{

        $url_Filter = $this->uri->uri_string();
        $filter = array();
        if (isset($_GET) && $_GET != null){
            //$url_Filter .= "/?p=".isset($_GET['p']) ? $_GET['p'] :  0 ."&h=". $_GET['h'] ? $_GET['h'] : 0 ."&l=".$_GET['l'] ? $_GET['l'] : 0 ."&c=".$_GET['c'] ? $_GET['c'] : 0 ."&t=".$_GET['t'] ? $_GET['t'] : 0 ."&pr=".$_GET['pr'] ? $_GET['pr'] : 0;
            $filter['p'] = $p = isset($_GET['p']) ? $_GET['p'] :  0 ;
            $filter['h'] = $h = isset($_GET['h']) ? $_GET['h'] :  0 ;
            $filter['l'] = $l = isset($_GET['l']) ? $_GET['l'] :  0 ;
            $filter['c'] = $c = isset($_GET['c']) ? $_GET['c'] :  0 ;
            $filter['t'] = $t = isset($_GET['t']) ? $_GET['t'] :  0 ;
            $filter['pr'] = $pr = isset($_GET['pr']) ? $_GET['pr'] :  0 ;

            $url_Filter .= "/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
        }else {
            $url_Filter .= "/?p=0&h=0&l=0&c=0&t=0&pr=0";
        }

        $param = $this->uri->segment(1);
        $getCateId = $this->category_model->getCateId($param);
        $config['per_page'] = 10;
		//$search = $param;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchCategory($getCateId[0]['cate_id'], $page, $config['per_page'], $filter);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/'.$param;
		$config['total_rows'] = $result['total_record'];
        /*
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
        */

        if($filter != null){
            $config['first_url'] = $config['base_url']."/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
            $this->pagination->suffix = "/?p=$p&h=$h&l=$l&c=$c&t=$t&pr=$pr";
        }
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
         $tinhnang = $this->utility_model->selectStatus('tbl_technology');

        $slider = $this->utility_model->selectSlider('tbl_slider');
		
		$detaildichvu = $this->utility_model->getDetail('tbl_category', 'cate_id',$getCateId[0]['cate_id']);
		
		$this->_data['seo'] = array(
				'metakey' => $detaildichvu->metakey,
				'metades' => $detaildichvu->metades,
		);
		$this->_data['main_container'] = $this->load->view('frontend/allproductsCate_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'pagination' => $data["paging"],
                'url_Filter' => $url_Filter,
                'silders' => $slider,
		), true);
		$this->load->view('frontend/layout_view', $this->_data);
	}
	
	
	public function deproduct()
	{
        $param = $this->uri->segment(1);
        $getCateId = $this->category_model->getCateIdProd($param);



		//$param = $this->uri->ruri_to_assoc();

		$config['per_page'] = 20;
		$page = $this->uri->segment(2);

		$result = $this->product_model->getAllSearchCategory2($getCateId[0]['cate_id'], $page, $config['per_page']);



		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
        /*
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
        */
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
         $tinhnang = $this->utility_model->selectStatus('tbl_technology');
		
		$detailproduct = $this->product_model->getDetail($this->uri->segment(1));
		
		$this->_data['seo'] = array(
			'metakey' => $detailproduct->metakey,
			'metades' => $detailproduct->metades,
		);
		
		$this->_data['main_container'] = $this->load->view('frontend/detailProducts_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                'tinhnang' => $tinhnang,
				'detailproduct' => $detailproduct,
				'pagination' => $data["paging"],
		), true);
		$this->load->view('frontend/layout_view', $this->_data);
	}
	
	
	public function checkout()
	{
		$param = $this->uri->ruri_to_assoc();
		$search = $param['id'];
		$config['per_page'] = 20;
		$page = $this->uri->segment(2);
		$result = $this->product_model->getAllSearchCategory($search, $page, $config['per_page']);
		$this->load->library('pagination');
		$config['base_url'] = base_url().'/dieu-hoa-khong-khi';
		$config['total_rows'] = $result['total_record'];
		if($search != ''){
			$this->pagination->suffix = '?search='. $search;
		}
		$config['use_page_numbers'] = false;
		$config['uri_segment'] = 2;
		$config['num_links'] = 1;
		$this->pagination->initialize($config);
		$data["paging"] = $this->pagination->create_links();
	
		$data['tbl_products'] = $result['tbl_products'];
	
		$khoanggia = $this->utility_model->selectStatus('tbl_aboutprice');
		$hangsanxuat = $this->utility_model->selectStatus('tbl_origin');
		$thuonghieu = $this->utility_model->selectStatus('tbl_brand');
		$congxuat = $this->utility_model->selectStatus('tbl_capacity');
         $tinhnang = $this->utility_model->selectStatus('tbl_technology');
	
		$detailproduct = $this->product_model->getDetailProduct($param['id']);
	
	
		$this->_data['main_container'] = $this->load->view('frontend/checkout_view', array(
				'tbl_products' => $data['tbl_products'],
				'khoanggia' => $khoanggia,
				'thuonghieu' => $thuonghieu,
				'hangsanxuat' => $hangsanxuat,
				'congxuat' => $congxuat,
                 'tinhnang' => $tinhnang,
				'detailproduct' => $detailproduct,
				'pagination' => $data["paging"],
		), true);
		$this->load->view('frontend/layout_view', $this->_data);
	}
	

	
}